using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.OpenApi.Models;
using WorkFlow;
using WorkFlow.Data;
using WorkFlow.Data.Model;
using Tewr.Blazor.FileReader;

var builder = WebApplication.CreateBuilder(args);

LogHelper.Init();
WorkFlowTool.InitConfig(builder.Configuration);

// Register CompanyApiAddressList
builder.Services.Configure<List<CompanyApiAddressEntity>>(builder.Configuration.GetSection("CompanyApiAddressList"));

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddFileReaderService();
builder.Services.AddSingleton<WorkFlowController>();
builder.Services.AddSingleton<ScheduledTask>();
builder.Services.AddSingleton<AutomationRun>();
builder.Services.AddTransient<DataManager>();
builder.Services.AddTransient<SqlHelper>();
builder.Services.AddSingleton<CommentTool>();
builder.Services.AddTransient<WorkFlowInfo>();
builder.Services.AddTransient<WorkFlowTool>();
builder.Services.AddTransient<List<WorkFlowInfo>>();
builder.Services.AddTransient<List<WorkFlowDetail>>();
builder.Services.AddTransient<List<ParameterEntity>>();
builder.Services.AddTransient<List<RuleEntity>>();
builder.Services.AddTransient<List<ScheduledTaskEntity>>();
builder.Services.AddTransient<List<TaskDetailEntity>>();
builder.Services.AddTransient<List<CompanyInfo>>();
builder.Services.AddTransient<List<PlatformInfo>>();
builder.Services.AddTransient<List<CompanyApiAddressEntity>>();
builder.Services.AddTransient<List<WorkFlowFileEntity>>();
builder.Services.AddControllers();
builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "WorkFlow", Version = "v1" });
});
var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();

}
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WorkFlow v1"));

//app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
